
local serviceId
function OnInit(id)
    print("[lua] decode["..id.."] OnInit")
    serviceId = id
end

function OnServiceMsg(source, buff)
    print("[lua] decode["..serviceId.."] OnServiceMsg buff="..buff)
    local n1 = 0
    local n2 = 0
    --解码
    if buff ~= "start" then
        n1, n2 = string.unpack("i4 i4", buff)
        if n1 > 3 then
            sunnet.KillService(serviceId)
            return
        end
    end
    --处理
    print("[lua] decode["..serviceId.."] n1:"..n1.." n2:"..n2)
    n1 = n1+1
    n2 = n2+2
    -- 编码
    buff = string.pack("i4 i4", n1, n2)
    sunnet.Send(serviceId, source, buff)
end

function OnExit()
    print("[lua] decode["..serviceId.."] OnExit")
end